<template>
  <div class="redirect-container"></div>
</template>
<script lang="ts" setup>
import {dmsDingLogin} from "/@/api/api";
import router from "/@/router";
import {ElMessage} from "element-plus";
import {useUserStore} from "/@/store/modules/user";
// 登录时判断 code
const route:any = useRoute()
const code = ref(route.query.code)
const userStore = useUserStore()
const state = ref(route.query.state);
const login = (form: any) => userStore.login(form)
const handleRoute = (list:any) => {
  return list === '/404' || list === '/403'
    ? '/'
    : list
}
/*watchEffect(()=>{
  if(code.value){
    // router.push('/redirect')
    const history_url:any = localStorage.getItem('redirect_code')
    dmsDingLogin({code:code.value,state:state.value}).then(async (data:any)=>{
      if(data.code == 200){
        await login(data.data.token).catch(() => {})
        await router.push(handleRoute(JSON.parse(history_url)))
        await localStorage.removeItem('redirect_code')
      }else {
        router.push('/login')
        // window.location.href = `${window.location.origin}/#/login}`
      }
    }).catch(()=>{
      router.push('/login')
      ElMessage({
        message: '登录失败',
        type: 'error',
      })
    })
  }
})*/
</script>
<style lang="scss" scoped>
</style>
